/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: avp_container.h
 *
 * Purpose: define container structure for av player
 *
 * Developer:
 *   wen.gu , 2022-01-19
 *
 * TODO:
 *
 ***************************************************************************/

/******************************************************************************
 **    INCLUDES
 ******************************************************************************/
#ifndef __AVP_CONTAINER_H__
#define __AVP_CONTAINER_H__

#include "avp_type.h"
#include "avp_error.h"
#include "avp_media.h"
#include "avp_packet.h"
#include "avp_media_stream.h"
/******************************************************************************
 **    MACROS
 ******************************************************************************/

/******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/
G_C_HEADER_START

typedef struct _avp_container_ops
{
    GErrc (*initialize)(GPHD* handle, const GSTR url);
    void (*finish)(GPHD handle);
    
    GErrc (*stream_get_info)(GPHD handle, GU32 index, avp_media_stream_t* stream_info);    
    GU32 (*stream_count)(GPHD handle);
    GU32 (*stream_count_ex)(GPHD handle, avp_media_category_t category);
    avp_media_category_t (*stream_category)(GPHD hadnle, GU32 index);

    GErrc (*stream_select)(GPHD handle, GU32 index); /** the index is in all streams, not for a special category */
    GErrc (*stream_unselect)(GPHD handle, GU32 index);
    
    GErrc (*read)(GPHD handle, avp_packet_t** pkt);
}avp_container_ops;

typedef struct _avp_container
{
    GPHD handle;
    const avp_container_ops* ops;
}avp_container_t;

/******************************************************************************
 **    CLASSES/FUNCTIONS DEFINITIONS
 ******************************************************************************/

G_API GErrc avp_container_initialize();
G_API void avp_container_finish();

G_API GErrc avp_container_register(const avp_container_ops* container_ops);
G_API GErrc avp_container_find(const GSTR url, avp_container_t* container);


G_API void avp_container_ops_finish(const avp_container_t* container);

G_API GErrc avp_container_ops_stream_get_info(const avp_container_t* container, GU32 index, avp_media_stream_t* stream_info);
G_API GErrc avp_container_ops_stream_select(const avp_container_t* container,  GU32 index); /** the index is in all streams, not for a special category */
G_API GErrc avp_container_ops_stream_unselect(const avp_container_t* container, GU32 index);

G_API avp_media_category_t avp_container_ops_stream_category(const avp_container_t* container, GU32 index);


G_API GErrc avp_container_ops_read(const avp_container_t* container, avp_packet_t** pkt);

G_API GU32 avp_container_ops_stream_count(const avp_container_t* container);
G_API GU32 avp_container_ops_stream_count_ex(const avp_container_t* container, avp_media_category_t category);




G_C_HEADER_END

#endif /** !__AVP_CONTAINER_H__ */

